#!/usr/bin/env groovy

def appname(name) {
  // String name = name
  return name
}

def branchTag(String branch) {
  def tagname = branch.substring(branch.lastIndexOf("/") + 1)
  return tagname
}

def updateJobList(deploylist,jobmap) {
  // 'release_dev:v1,release_test:v2'
  def job_list = jobmap.split(',')
  def update_job_list = []
  def update_map = [:]
  for(String line : job_list) {
    def jobs = line.split(':')
    update_map[jobs[0]] = jobs[1]
  }
  def deploy_dev_list = deploylist.split(',')
  for(String deploy_dev : deploy_dev_list){
    def job_name = update_map.get(deploy_dev)
    update_job_list.add(job_name)
  }
  // for(int i =0 ;i < deploylist.size(); i++) {
  //   def job_name = update_map.get(deploylist[i])
  //   update_job_list.add(job_name)
  // }
  return update_job_list.join(',')
}

def buildDir(build_dir) {
  if(build_dir == null) {
    return
  } else{
    return build_dir
  }
}